﻿using System;
using System.Linq;
using Solution.BusinessObject;
using Solution.Controls;
using Solution.Core;

namespace Solution
{
    public partial class Author : PageBase
    {
        private Author _author;

        protected void Page_Load(object sender, EventArgs e)
        {
            var authorDetail = (AuthorDetail) this.LoadControl("Controls/AuthorDetail.ascx");

            var authorId = 0;

            if (Request["ath"] != null)
            {
                authorId = Convert.ToInt32(Request["ath"]);
            }

            if (authorId <= 0)
            {
                return;
            }
            _author = CommonBO.MasterEDM.Authors
                .FirstOrDefault(t => t.Id == authorId);
            authorDetail.Author = _author;


            Controls.Add(authorDetail);

            var albums = CommonBO.MasterEDM.Contents
                .Where(t => t.Author.Id == _author.Id).ToList();

            rptAlbums.DataSource = albums;
            rptAlbums.DataBind();

            var authorsInCategory = new AuthorBO().GetAuthorsInCategory(_author);
            rptAuthors.DataSource = authorsInCategory;
            rptAuthors.DataBind();
        }
    }
}